function basePath() {
	// 获取当前网址，如： http://localhost:8080/ems/Pages/Basic/Person.jsp
	var curWwwPath = window.document.location.href;
	// 获取主机地址之后的目录，如： /ems/Pages/Basic/Person.jsp
	var pathName = window.document.location.pathname;
	var pos = curWwwPath.indexOf(pathName);
	// 获取主机地址，如： http://localhost:8080
	var localhostPath = curWwwPath.substring(0, pos);
	// 获取带"/"的项目名，如：/ems
	var projectName = pathName
			.substring(0, pathName.substr(1).indexOf('/') + 1);
	// 获取项目的basePath http://localhost:8080/ems/
	var basePath = localhostPath + projectName + "/";
	return basePath;
};

jQuery(document).ready(function() {
	// 获取主键
	var pk = window.parent.document.getElementById("ifModal3").contentWindow.location.search.substring(1);
	pk = pk.replace('pk=', '');

	init(pk);
	initQuestion(pk);

});

function init(pk) {
	var da = {};
	da.QUESTIONNAIREID = pk;
	da.pageNum = "1";
	da.pageSize = "1";
	$.ajax({
		type : "post",
		url : basePath() + 'question/list.do',
		data : JSON.stringify(da),
		dataType : "json",
		contentType : 'application/json;charset=UTF-8',
		success : function(data) {
			$("#pk3").val(data.rows[0].QUESTIONNAIREID);
			$("#title3").html(data.rows[0].QUESTIONNAIRETITLE);
			$("#disc3").text(data.rows[0].QUESTIONNAIREDISC);
		}
	});
}

function initQuestion(pk) {
	var da = {};
	da.QUESTIONNAIREID = pk;
	da.pageNum = "1";
	da.pageSize = "999";
	$.ajax({
		type : "post",
		url : projectPath + 'question/qlist.do',
		data : JSON.stringify(da),
		dataType : "json",
		async : false,
		contentType : 'application/json;charset=UTF-8',
		success : function(data) {
			var questions = data.rows;
			var info = "";
			num = questions.length;
			for (var i = 0; i < questions.length; i++) {
				var question = questions[i];
				info += '<div class="form-group"><div class="col-sm-1"></div><div class="col-sm-10"><hr style="height:1px;border:none;border-top:1px solid #555555;" />';
				if (question.QUESTIONTYPE == '1') {
					info += '<h4 id="' + question.QUESTIONID + '">' + question.QUESTION + '</h4>';
					var items = question.QUESTIONITEM;
					var item = items.split(",");
					for (var j = 0; j < item.length; j++) {
						info += '<input type="radio" value="' + item[j] + '" name="question' + i + '">' + item[j] + '</input><br>';
					}
				} else if (question.QUESTIONTYPE == '2') {
					info += '<h4 id="' + question.QUESTIONID + '">' + question.QUESTION + '(多选)</h4>';
					var items = question.QUESTIONITEM;
					var item = items.split(",");
					for (var j = 0; j < item.length; j++) {
						info += '<input type="checkbox" value="' + item[j] + '" name="question' + i + '">' + item[j] + '</input><br>';
					}
				}
				info += '</div><div class="col-sm-1"></div></div>';
			}
			$("#info").html(info);
		}
	});
}